package com.ecloud.support.generator.service.impl;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ecloud.common.base.result.Result;
import com.ecloud.common.base.result.ResultBuilder;
import com.ecloud.common.base.result.ResultStatus;
import com.ecloud.common.base.result.RowsBuilder;
import com.ecloud.common.data.annotation.DynamicDS;
import com.ecloud.common.utils.check.LongUtils;
import com.ecloud.support.generator.mapper.TableInfoMapper;
import com.ecloud.support.generator.model.dto.TableInfoDto;
import com.ecloud.support.generator.model.entity.TableInfoPo;
import com.ecloud.support.generator.model.vo.TableInfoVo;
import com.ecloud.support.generator.service.iface.ITableInfoService;

/**
 * TableInfoService
 *
 * @author LiuGangQiang Create in 2021/04/15
 */
@Service
@DynamicDS("#header.dbid")
public class TableInfoService extends ServiceImpl<TableInfoMapper, TableInfoPo> implements ITableInfoService {

    @Override
    public Result<?> queryList(TableInfoDto dto) {
        /* 构造分页查询 */
        IPage<TableInfoVo> page = this.getBaseMapper().selectLimit(new Page<>(dto.getPage(), dto.getRows()), dto);
        if (LongUtils.isGtZero(page.getTotal())) {
            /* 转换 */
            return ResultBuilder.build(ResultStatus.OK, RowsBuilder.build(page.getTotal(), page.getRecords()));
        }
        return ResultBuilder.build(ResultStatus.DATA_NOT_FOUND, RowsBuilder.build());
    }
}
